package aipay.mobile.server;

import java.io.IOException;

import org.json.JSONObject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

public class ConfigurationWS {
	private final static String URL ="http://192.168.1.222/Aipay/Service.asmx";
	private final static String NAMESPACE ="http://tempuri.org/";
	
	public ConfigurationWS(){
	}
	
	public String GetData(final String NAMEMETHOD){
		String jarr =null;
		
		SoapObject request = new SoapObject(NAMESPACE, NAMEMETHOD);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		final String SOAP_ACTION = NAMESPACE+NAMEMETHOD;
		 //tạo đối tượng HttpTransportSE
        HttpTransportSE http = new HttpTransportSE(URL);
        
        try {
        	//goi server
			http.call(SOAP_ACTION, envelope);
			SoapPrimitive respon = (SoapPrimitive) envelope.getResponse();
			jarr=respon.toString();
			Log.e("jarr",jarr);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return jarr;
	}
	
	public String UpGetData(final String NAMETHOD,String json){

		String jarr = null;
		SoapObject request = new SoapObject(NAMESPACE, NAMETHOD);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		request.addProperty("json",json);
		envelope.setOutputSoapObject(request);
		final String SOAP_ACTION = NAMESPACE+NAMETHOD;
		 //tạo đối tượng HttpTransportSE
        HttpTransportSE http = new HttpTransportSE(URL);
        
        try {
        	//goi server
			http.call(SOAP_ACTION, envelope);
			SoapPrimitive respon = (SoapPrimitive) envelope.getResponse();
			jarr =respon.toString();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return jarr;
	
	}
}
